package com.elai.web.controller.baseconfig;

import com.elai.common.annotation.Log;
import com.elai.common.core.controller.BaseController;
import com.elai.common.core.domain.AjaxResult;
import com.elai.common.core.page.TableDataInfo;
import com.elai.common.enums.BusinessType;
import com.elai.common.utils.poi.ExcelUtil;
import com.elai.baseconfig.domain.OperateEquityTypeDO;
import com.elai.baseconfig.service.OperateEquityTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 权益类型Controller
 *
 * @author elai
 * @date 2021-04-10
 */
@RestController
@RequestMapping("/config/equitytype")
public class OperateEquityTypeController extends BaseController
{
    @Autowired
    private OperateEquityTypeService operateEquityTypeService;

    /**
     * 查询权益类型列表
     */
    @PreAuthorize("@ss.hasPermi('config:equitytype:list')")
    @GetMapping("/list")
    public TableDataInfo list(OperateEquityTypeDO operateEquityType)
    {
        startPage();
        List<OperateEquityTypeDO> list = operateEquityTypeService.selectOperateEquityTypeList(operateEquityType);
        return getDataTable(list);
    }

    @GetMapping("/getAllTypeList")
    public TableDataInfo getAllTypeList(OperateEquityTypeDO operateEquityType)
    {
        List<OperateEquityTypeDO> list = operateEquityTypeService.selectOperateEquityTypeList(operateEquityType);
        return getDataTable(list);
    }

    /**
     * 导出权益类型列表
     */
    @PreAuthorize("@ss.hasPermi('config:equitytype:export')")
    @Log(title = "权益类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OperateEquityTypeDO operateEquityType)
    {
        List<OperateEquityTypeDO> list = operateEquityTypeService.selectOperateEquityTypeList(operateEquityType);
        ExcelUtil<OperateEquityTypeDO> util = new ExcelUtil<OperateEquityTypeDO>(OperateEquityTypeDO.class);
        return util.exportExcel(list, "equitytype");
    }

    /**
     * 获取权益类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('config:equitytype:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(operateEquityTypeService.selectOperateEquityTypeById(id));
    }

    /**
     * 新增权益类型
     */
    @PreAuthorize("@ss.hasPermi('config:equitytype:add')")
    @Log(title = "权益类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OperateEquityTypeDO operateEquityType)
    {
        return toAjax(operateEquityTypeService.insertOperateEquityType(operateEquityType));
    }

    /**
     * 修改权益类型
     */
    @PreAuthorize("@ss.hasPermi('config:equitytype:edit')")
    @Log(title = "权益类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OperateEquityTypeDO operateEquityType)
    {
        return toAjax(operateEquityTypeService.updateOperateEquityType(operateEquityType));
    }

    /**
     * 删除权益类型
     */
    @PreAuthorize("@ss.hasPermi('config:equitytype:remove')")
    @Log(title = "权益类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(operateEquityTypeService.deleteOperateEquityTypeByIds(ids));
    }
}
